package com.luodim.dialogtest;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private DialogView mDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setFullScreen();
        setContentView(R.layout.activity_main);
        Button btn = (Button) findViewById(R.id.btn_dialog);
        Button btn2 = (Button) findViewById(R.id.btn_dialog_2);
//        mDialog = (DialogView) findViewById(R.id.my_dialog);
        btn.setTag("1");
        btn2.setTag("2");
        btn.setOnClickListener(this);
        btn2.setOnClickListener(this);
        mDialog = new DialogView(this);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        this.addContentView(mDialog, params);
    }

    @Override
    public void onClick(View v) {
        String tag = (String) v.getTag();
        if ("1".equals(tag)) {
            mDialog.initView(DialogView.ONE_PIC);
        } else if ("2".equals(tag)) {
            mDialog.initView(DialogView.TWO_PIC);
        }
        mDialog.showDialog();
    }

    private void setFullScreen() {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
    }
}
